package c.c.b.b.g;

import com.huawei.hms.framework.common.ContainerUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/* compiled from: UrlBuilder */
public class d {
    public final Map<String, List<String>> a = new LinkedHashMap();
    public String b;

    public d(String str) {
        this.b = str;
    }

    public void a(String str, double d) {
        List list = (List) this.a.get(str);
        if (list == null) {
            list = new LinkedList();
        }
        list.add(String.valueOf(d));
        this.a.put(str, list);
    }

    public void b(String str, int i) {
        List list = (List) this.a.get(str);
        if (list == null) {
            list = new LinkedList();
        }
        list.add(String.valueOf(i));
        this.a.put(str, list);
    }

    public void c(String str, String str2) {
        List list = (List) this.a.get(str);
        if (list == null) {
            list = new LinkedList();
        }
        list.add(String.valueOf(str2));
        this.a.put(str, list);
    }

    public String toString() {
        if (this.a.isEmpty()) {
            return this.b;
        }
        String str;
        Map map = this.a;
        String str2 = "UTF-8";
        StringBuilder stringBuilder = new StringBuilder();
        Iterator it = map.entrySet().iterator();
        while (true) {
            str = "&";
            if (!it.hasNext()) {
                break;
            }
            Entry entry = (Entry) it.next();
            try {
                String encode = URLEncoder.encode((String) entry.getKey(), str2);
                List<String> list = (List) entry.getValue();
                if (list != null && list.size() > 0) {
                    for (String str3 : list) {
                        String str32;
                        if (str32 != null) {
                            try {
                                str32 = URLEncoder.encode(str32, str2);
                            } catch (UnsupportedEncodingException e) {
                                throw new IllegalArgumentException(e);
                            }
                        }
                        str32 = "";
                        if (stringBuilder.length() > 0) {
                            stringBuilder.append(str);
                        }
                        stringBuilder.append(encode);
                        if (!str32.isEmpty()) {
                            stringBuilder.append(ContainerUtils.KEY_VALUE_DELIMITER);
                            stringBuilder.append(str32);
                        }
                    }
                }
            } catch (UnsupportedEncodingException e2) {
                throw new IllegalArgumentException(e2);
            }
        }
        String stringBuilder2 = stringBuilder.toString();
        str2 = this.b;
        if (str2 == null || str2.length() == 0) {
            return stringBuilder2;
        }
        StringBuilder stringBuilder3;
        if (this.b.indexOf(63) >= 0) {
            stringBuilder3 = new StringBuilder();
            stringBuilder3.append(this.b);
            stringBuilder3.append(str);
        } else {
            stringBuilder3 = new StringBuilder();
            stringBuilder3.append(this.b);
            stringBuilder3.append("?");
        }
        stringBuilder3.append(stringBuilder2);
        return stringBuilder3.toString();
    }
}
